function red() {
  console.log("red");
}
function green() {
  console.log("green");
}
function yellow() {
  console.log("yellow");
}
//红灯三秒打印一次，绿灯一秒打印一次，黄2两打印一次，三个灯不断交替
function trafficLight() {
  setInterval(function() {
    red();
    setTimeout(green, 1000);
    setTimeout(yellow, 2000);
  }, 3000);
}
trafficLight();